﻿<UserControl x:Class="MissedMemo.MeatAndCheeseDisc.OrderEntry.viewOrderDetails"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:local="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderEntry"
    Height="540" Width="400">

    <UserControl.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="resAddEditStyles.xaml" />
                <ResourceDictionary Source="resCommonStyles.xaml" />
                <ResourceDictionary Source="resAnimations.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="OrderItemTemplate">
                <DockPanel>
                    <Button Content="X" Foreground="Red" FontWeight="Bold" ToolTip="Delete Item" Click="btnDeleteItem_Click" />
                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" Text="{Binding Type}" />
				</DockPanel >
            </DataTemplate>

            <Style x:Key="AddEditOrderItemListBorderStyle" TargetType="Border" >
                <Setter Property="BorderBrush" Value="{StaticResource brushListOrderItemsBorder}" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="Margin" Value="6" />
                <Setter Property="Padding" Value="3" />
            </Style>

            <local:WinFormsControlVisibilityConverter x:Key="WinFormsControlVisibilityConverter" />
            <local:GridColumnWidthConverter x:Key="GridColumnWidthConverter" />
            <local:OrderStateToCheckStateConverter x:Key="OrderStateToCheckStateConverter" />
            <local:OrderStateToCheckEnabledConverter x:Key="OrderStateToCheckEnabledConverter" />

        </ResourceDictionary>
    </UserControl.Resources>
	
    
    <Grid Margin="12,18,12,12" >

       <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>


        <Border Grid.Row="0" Style="{StaticResource outerInsetBorderStyle}" >
            <Border x:Name="AddEditInnerBorder" Style="{StaticResource innerInsetBorderStyle}" Padding="6" Background="{StaticResource brushAddEditView}" > 
                <Grid>
                
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="columnImages" Width="1*" />
                        <ColumnDefinition Width="5*"/>
                    </Grid.ColumnDefinitions>
                    
                    
                    <!-- List of items added to the current order -->

                    <Border Grid.Row="0" Grid.Column="1" Name="OrderItemListBorder" Style="{StaticResource AddEditOrderItemListBorderStyle}"
                            Background="{StaticResource brushListOrderItems}" >
                        <ListView Grid.Row="0" Grid.Column="1" Name="listOrderItems" BorderThickness="0" Background="{x:Null}"
                                  ItemsSource="{Binding Items}" MouseDoubleClick="listItems_DoubleClick" >
                            <ListView.View>
                                <GridView >

                                    <!-- There is currently no built-in support for AUTOMATIC column sizing, so we must calculate... -->
                                    <GridViewColumn Header="Item" CellTemplate="{StaticResource OrderItemTemplate}"
                                            Width="{Binding ActualWidth, ElementName=listOrderItems,
                                            Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.50}" />
                                    <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Size}"
                                            Width="{Binding ActualWidth, ElementName=listOrderItems,
                                            Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.30}" />
                                    <GridViewColumn Header="Price" DisplayMemberBinding="{Binding Price,
                                            Converter={StaticResource FormattedTextConverter}, ConverterParameter='{}{0:C2}'}"
                                            Width="{Binding ActualWidth, ElementName=listOrderItems,
                                            Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.20}" />
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </Border>

                    
                    <!-- Container for embedded pizza/drink/dessert edit views -->

                    <ContentControl Grid.Row="0" Grid.Column="1" x:Name="EditItemViewContainer" RenderTransformOrigin="0.5,0.5" >
                    	<ContentControl.RenderTransform>
                    		<TransformGroup>
                    			<ScaleTransform ScaleX="1" ScaleY="1"/>
                    			<SkewTransform AngleX="0" AngleY="0"/>
                    			<RotateTransform Angle="0"/>
                    			<TranslateTransform X="0" Y="0"/>
                    		</TransformGroup>
                    	</ContentControl.RenderTransform>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="ComboBox">
                                    <Setter Property="Background" Value="Transparent" />
                                </Style>
                            </Grid.Resources>
                            <local:viewAddEditPizza x:Name="PizzaEditView" />
                            <local:viewAddEditDrink x:Name="DrinkEditView" />
                            <local:viewAddEditDessert x:Name="DessertEditView" />
                        </Grid>
                    </ContentControl>

                    
                    <!-- Images (auto-size to fit col. width)  -->
                    
                    <Grid Grid.Row="0" Grid.Column="0" x:Name="gridImageTriggers" >
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition Height="0.5*" />
                        </Grid.RowDefinitions>
                        <ContentControl Grid.Row="0" Style="{StaticResource BorderedImageStyle}"
                                        Name="imagePizza" MouseLeftButtonDown="btnAddPizza_Click" >
                            <Image Source="Resources\Pizza.png"  />
                        </ContentControl>
                        <ContentControl Grid.Row="1" Style="{StaticResource BorderedImageStyle}"
                                        Name="imageDrink" MouseLeftButtonDown="btnAddDrink_Click" >
                            <Image Source="Resources\Drink.png"  />
                        </ContentControl>
                        <ContentControl Grid.Row="2" Style="{StaticResource BorderedImageStyle}"
                                        Name="imageDessert" MouseLeftButtonDown="btnAddDessert_Click" >
                            <Image Source="Resources\Dessert.png"  />
                        </ContentControl>
                    </Grid>

                    
                    <!-- OK/Cancel Buttons -->

                    <DockPanel Name="buttonPanel" Grid.Row="1" Grid.Column="1" Margin="6" Visibility="Collapsed"
                               Style="{StaticResource OKCancelButtonPanelStyle}" >
                        <Button Content="Cancel" Margin="3,0" Click="btnCancel_Click"/>
                        <Button Content="OK" Click="btnOK_Click" />
                    </DockPanel>

                </Grid>           
            </Border>
        </Border>

        <!-- TOTAL COST calculation area -->
        
        <Grid Grid.Row="1" Margin="12" >

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Text="Ordered:" />
            <TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0"
                       Text="{Binding DateTimeOrderPlaced, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0:M/d/yy  h:mm tt}'}" />
            
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Expected:" />
            
            <!-- Show/hide WinForms control during animation of WPF container -->
            
            <WindowsFormsHost Grid.Row="1" Grid.Column="1" Margin="8,0,0,0"
             Visibility="{Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl},
                Converter={StaticResource WinFormsControlVisibilityConverter}}" >
                <winforms:DateTimePicker x:Name="datepickerOrderExpected" Width="140" Format="Custom"
                 CustomFormat="M/dd/yy  h:mm tt" ValueChanged="OnEditDateTimeOrderExpected" />
            </WindowsFormsHost>
            
            <CheckBox Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Content="Done:"
                      IsChecked="{Binding ProcessingState, Converter={StaticResource OrderStateToCheckStateConverter}}"
                      IsEnabled="{Binding ProcessingState, Converter={StaticResource OrderStateToCheckEnabledConverter}}" />
            <TextBlock Grid.Row="5" Grid.Column="1" VerticalAlignment="Center" Margin="8,0"
                       Text="{Binding DateTimeOrderCompleted, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0:M/d/yy  h:mm tt}'}" />
            
            <TextBlock Name="txtSubTotal" Grid.Row="0" Grid.Column="3" Text="SubTotal:" />
            <TextBlock Grid.Row="0" Grid.Column="4"
                       Text="{Binding CostPreTax, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />
		    
            <TextBlock Grid.Row="1" Grid.Column="3" Text="Local Tax:" />
            <TextBlock Grid.Row="1" Grid.Column="4" 
                       Text="{Binding Tax, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />
            
            <Line Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="2" Stroke="{Binding Foreground, ElementName=txtSubTotal}" X2="120" />
            <TextBlock Grid.Row="2" Grid.Column="4" FontWeight="Bold"
                       Text="{Binding TotalCost, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />

        </Grid>

    </Grid>
    
</UserControl>
